import 'package:flutter/material.dart';
import '../page/shop_page.dart';
import '../page/social_hub_page.dart';
import '../page/user_page.dart';
import '../util/my_colors.dart';

import 'cart_page.dart';
import 'news_page.dart';

class IndexPage extends StatefulWidget {
  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  @override
  Widget build(BuildContext context) {
    return _PageBody();
  }
}

class _PageBody extends StatefulWidget {
  @override
  __PageBodyState createState() => __PageBodyState();
}

class __PageBodyState extends State<_PageBody> {
  int _bottomBarIndex = 0;
  List<Widget> _pages = [
    NewsPage(),
    SocialHubPage(),
    ShopPage(),
    CartPage(),
    UserPage()
  ];

  List<BottomNavigationBarItem> _items = new List();

  @override
  void initState() {
    _items.addAll([
      BottomNavigationBarItem(
          title: Text(
            "资讯",
          ),
          icon: Icon(Icons.message)),
      BottomNavigationBarItem(
          title: Text(
            "圈子",
          ),
          icon: Icon(Icons.public)),
      BottomNavigationBarItem(
          title: Text(
            "商城",
          ),
          icon: Icon(Icons.shop)),
      BottomNavigationBarItem(
          title: Text(
            "购物车",
          ),
          icon: Icon(Icons.shopping_cart)),
      BottomNavigationBarItem(
          title: Text(
            "我的",
          ),
          icon: Icon(Icons.person)),
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_bottomBarIndex],
      bottomNavigationBar: BottomNavigationBar(
          backgroundColor: MyColors.bgColor,
          type: BottomNavigationBarType.fixed,
          currentIndex: _bottomBarIndex,
          unselectedItemColor: Colors.black,
          selectedItemColor: Colors.blue,
          onTap: (value) {
            setState(() {
              _bottomBarIndex = value;
            });
          },
          items: _items
      ),
    );
  }
}
